export interface KeyupParams {
  callback?: () => void
}

export function useKeyup({ callback }: KeyupParams) {
  function handleKeyup(event) {
    const keyPress = event.key
    processKey(keyPress)
  }
  function processKey(key) {
    if (callback) {
      callback(key)
    }
  }

  function init() {
    document.removeEventListener('keyup', handleKeyup)
    document.addEventListener('keyup', handleKeyup)
  }

  return { init }
}
